  function initAjax() {
     try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
     try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
     alert("XMLHttpRequest not supported");
     return null;
  };

  //Get all district
  function getDistrict(){
    document.getElementById("form_district").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
    document.getElementById("form_tambon").innerHTML = '-';
     var req = initAjax();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById("form_district").innerHTML=req.responseText; 
               } 
          }
     };

    var pro_id = document.getElementById("form_pro_id_").value;
    req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=District&pro_id="+pro_id+"&sel=1&enable=1"); //create connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
    req.send(null); //sending
  }


  //Get all district by province ID
  function getDistrictByProvinceID(){
    var pro_id = document.getElementById("form_pro_id_").value;

    if(pro_id == 0){
      document.getElementById("form_district").innerHTML=""; 
      document.getElementById("form_tambon").innerHTML=""; 
      document.getElementById("form_village").innerHTML=""; 
      document.getElementById("form_house_no").innerHTML=""; 
    }else{
      document.getElementById("form_tambon").innerHTML=""; 
      document.getElementById("form_village").innerHTML=""; 
      document.getElementById("form_house_no").innerHTML=""; 
      document.getElementById("form_district").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
      var req = initAjax();
      req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById("form_district").innerHTML=req.responseText; 
               } 
          }
      };

      req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=District&pro_id="+pro_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //sending
    }
  }

  //Get all tambon
  function getTambon(){
    document.getElementById("form_tambon").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
     var req = initAjax();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById("form_tambon").innerHTML=req.responseText; 
               } 
          }
     };

    var pro_id = document.getElementById("form_pro_id_").value;
    var dis_id = document.getElementById("form_dis_id_").value;
    req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=Tambon&pro_id="+pro_id+"&dis_id="+dis_id); //create connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
    req.send(null); //sending
  }

  //Get all tambon by province ID
  function getTambonByDistrictID(){

    var pro_id = document.getElementById("form_pro_id_").value;
    var dis_id = document.getElementById("form_dis_id_").value;

    if(dis_id == 0){
      document.getElementById("form_tambon").innerHTML=""; 
      document.getElementById("form_village").innerHTML=""; 
      document.getElementById("form_house_no").innerHTML=""; 
    }else{
      document.getElementById("form_village").innerHTML=""; 
      document.getElementById("form_house_no").innerHTML=""; 
      document.getElementById("form_tambon").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
       var req = initAjax();
       req.onreadystatechange = function () { 
            if (req.readyState==4) {
                 if (req.status==200) {
                      document.getElementById("form_tambon").innerHTML=req.responseText; 
                 } 
            }
       };


      req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=Tambon&pro_id="+pro_id+"&dis_id="+dis_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //sending
    }
  }


  //Get all village
  function getVillage(){
    document.getElementById("form_village").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
     var req = initAjax();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById("form_village").innerHTML=req.responseText; 
               } 
          }
     };

    var pro_id = document.getElementById("form_pro_id_").value;
    var dis_id = document.getElementById("form_dis_id_").value;
    var tam_id = document.getElementById("form_tam_id_").value;
    req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=Village&pro_id="+pro_id+"&dis_id="+dis_id+"&tam_id="+tam_id); //create connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
    req.send(null); //sending
  }

  //Get all village by province ID
  function getVillageByTambonID(){
    var pro_id = document.getElementById("form_pro_id_").value;
    var dis_id = document.getElementById("form_dis_id_").value;
    var tam_id = document.getElementById("form_tam_id_").value;

    if(tam_id == 0){
      document.getElementById("form_village").innerHTML=""; 
      document.getElementById("form_house_no").innerHTML=""; 
    }else{
      document.getElementById("form_house_no").innerHTML=""; 
      document.getElementById("form_village").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
       var req = initAjax();
       req.onreadystatechange = function () { 
            if (req.readyState==4) {
                 if (req.status==200) {
                      document.getElementById("form_village").innerHTML=req.responseText; 
                 } 
            }
       };

      req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=Village&pro_id="+pro_id+"&dis_id="+dis_id+"&tam_id="+tam_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //sending
    }
  }


  //Get all house no.
  function getHouseNo(){
    document.getElementById("form_house_no").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
     var req = initAjax();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    document.getElementById("form_house_no").innerHTML=req.responseText; 
               } 
          }
     };

    var pro_id = document.getElementById("form_pro_id_").value;
    var dis_id = document.getElementById("form_dis_id_").value;
    var tam_id = document.getElementById("form_tam_id_").value;
    var vil_id = document.getElementById("form_vil_id_").value;
      req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=HouseNo&pro_id="+pro_id+"&dis_id="+dis_id+"&tam_id="+tam_id+"&vil_id="+vil_id); //create connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
    req.send(null); //sending
  }

  //Get all house no. by village ID
  function getHouseNoByVillageID(){
    var pro_id = document.getElementById("form_pro_id_").value;
    var dis_id = document.getElementById("form_dis_id_").value;
    var tam_id = document.getElementById("form_tam_id_").value;
    var vil_id = document.getElementById("form_vil_id_").value;

    if(vil_id == 0){
      document.getElementById("form_house_no").innerHTML=""; 
    }else{
      document.getElementById("form_house_no").innerHTML = '<IMG SRC="modules/VoteDataCenter/pnimages/ajax-loader-2.gif">';
       var req = initAjax();
       req.onreadystatechange = function () { 
            if (req.readyState==4) {
                 if (req.status==200) {
                      document.getElementById("form_house_no").innerHTML=req.responseText; 
                 } 
            }
       };

      req.open("POST", "index.php?module=VoteDataCenter&type=ajax&func=list&ctrl=HouseNo&pro_id="+pro_id+"&dis_id="+dis_id+"&tam_id="+tam_id+"&vil_id="+vil_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //sending
    }
  }
